<%@page import="pl.org.waff.repository.Comment, pl.org.waff.WaffServlet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="repository" class="pl.org.waff.repository.InMemoryContentCache" scope="application" />
<jsp:useBean id="cmswitch" class="pl.org.waff.cm.CMSwitch" scope="session" />
<jsp:useBean id="waffuser" class="pl.org.waff.WaffUser" scope="session" />
<jsp:useBean id="comment" class="pl.org.waff.repository.Comment" scope="request" />
<div>
    <%
        String asc=(String)request.getAttribute(WaffServlet.PATH_ATTRIBUTE_NAME);
        boolean afterSavingComment=(asc!=null&&asc.indexOf("comment.save.do")>=0);
        String cId = cmswitch.getCommentid();
        if ("new".equals(comment.getId())) {
                if (!("-1".equals(cId) || cId == null)) {
                    Comment cmnt = repository.getComment(cId);
                    if (cmnt != null) {
                        comment = cmnt;
                    }
                }
                if ("new".equals(comment.getId())) {
                    comment.setAuthor(waffuser.getAlias());
                    comment.setParent(cmswitch.getDocid());
                }
            }
%>
<table width="100%">
            <tr>
                <td>
                    <% if(afterSavingComment){ out.print("comment saved");}%>
                </td>
            </tr>
        </table>
    <form action="comment.save.do" method="POST">
        <input name="id" value="<%=comment.getId()%>" type="hidden"/>
        <input name="parent" value="<%=comment.getParent()%>" type="hidden"/>
        <table width="100%">
            <tr><td>Title<br/><input name="title" type="text" value="<%=comment.getTitle()%>"/></td></tr>
            <tr><td>Author<br/><input name="author" value="<%=comment.getAuthor()%>" type="text"/></td></tr>
            <tr><td>E-mail<br/><input name="email" value="<%=comment.getEmail()%>" type="text"/></td></tr>
            <tr><td>Website<br/><input name="website" value="<%=comment.getWebsite()%>" type="text"/></td></tr>
            <tr><td>Content<br/><textarea name="content" rows="10" wrap="soft"><%=comment.getContent()%></textarea></td></tr>
            <tr><td><button type="submit">Save</button></td></tr>
        </table>
    </form>
</div>